use clap::{Arg, Command};
use std::{error::Error};

mod hdc;
mod utils;

fn main() -> Result<(), Box<dyn Error>> {
    let matches = Command::new("hilog_tool")
        .version("1.0")
        .author("huawei")
        .about("Filter logs based on a time range")
        .arg(
            Arg::new("start_time")
                .short('s')
                .long("start-time")
                .value_name("START_TIME")
                .help("The start time for filtering logs (format: MM-DD)"),
        )
        .arg(
            Arg::new("end_time")
                .short('e')
                .long("end-time")
                .value_name("END_TIME")
                .help("The end time for filtering logs (format: MM-DD)"),
        )
        .get_matches();

    let start_time = matches.get_one::<String>("start_time").map(|s| s.as_str());
    let end_time = matches.get_one::<String>("end_time").map(|s| s.as_str());

    let device = hdc::get_device()?;
    println!("Current device: {}", device);

    let log_path = utils::create_device_log_file(&device)?;
    let _ = hdc::get_hilog(&log_path, start_time, end_time)?;
    println!("Saved log files at: {}", log_path);
    Ok(())
}
